package 笔试.阅文;

import 算法.NiuKe.TreeNode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

/**
 * @author:谢君臣
 * @Date:2021/10/21-19:55
 * @version:1.0
 * @function:
 */
public class Main {
    public static void main(String[] args) {

    }

    public boolean isSameTree (TreeNode p, TreeNode q) {
        // write code here
        if(p==null&&q==null)
            return true;
        if(p==null||q==null)
            return false;
        boolean flag = p.val == q.val;
        if (!flag)
            return false;
        boolean l = isSameTree(p.left,q.left);
        boolean r = isSameTree(p.right,q.right);
        return r == l && l;

    }
    public int findLucky (int[] arr) {
        // write code here
        int max = -1;
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        for (int num : arr) {
            hashMap.put(num,hashMap.getOrDefault(num,0)+ 1);
        }
        Iterator<Integer> iterator = hashMap.keySet().iterator();
        while (iterator.hasNext()) {
            Integer key = iterator.next();
            if (hashMap.get(key)==key) max = Math.max(max,key);
        }
        return max;
    }
}
